#include "CreateProjectDialog.hpp"
#include "CheckURLSpecialSymbol.hpp"

CreateProjectDialog::CreateProjectDialog()
  : labProject("项目名称")
  , labDescribe("项目描述词")
  , labInfo("")
  , btnOK("确定")
  , btnCancel("取消")
  , buttonBox(Gtk::Orientation::HORIZONTAL)
{
  set_destroy_with_parent(true);
  set_default_size(100,100);
  set_title("创建项目");
  set_child(m_grid);
  m_grid.set_column_spacing(4);
  m_grid.set_row_spacing(4);
  m_grid.attach(labProject,0,0);
  m_grid.attach(entryProject,1,0);
  m_grid.attach(labDescribe,0,1);
  m_grid.attach(entryDescribe,1,1);
  m_grid.attach(labInfo,0,2,2,1);
  m_grid.attach(buttonBox,0,3,2,1);
  buttonBox.append(btnOK);
  buttonBox.append(btnCancel);
  btnOK.set_hexpand();
  btnCancel.set_hexpand();
  btnOK.signal_clicked().connect(sigc::mem_fun(*this,&CreateProjectDialog::on_btnOK_click));
  btnCancel.signal_clicked().connect(sigc::mem_fun(*this,&CreateProjectDialog::on_btnCancel_click));
}

CreateProjectDialog::~CreateProjectDialog()
{

}


bool CreateProjectDialog::GetSucessStatus()
{
  return SucessStatus;
}

std::string CreateProjectDialog::GetProjectName()
{
  return entryProject.get_text();
}

std::string CreateProjectDialog::GetDescribe()
{
  return entryDescribe.get_text();
}

void CreateProjectDialog::on_btnOK_click()
{
  if(CheckSpectialSymbol(entryDescribe.get_text()) && CheckSpectialSymbol(entryProject.get_text()))
  {
    SucessStatus=true;
    set_visible(false);
  }
  else
  {
    labInfo.set_text("请检查输入内容是否有特殊符号");
  }
}

void CreateProjectDialog::on_btnCancel_click()
{
  SucessStatus=false;
  set_visible(false);
}
